unit Con_NaturezaOper;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Mask, Grids,
  DBGrids, dbtables, db, TFlatButtonUnit;

type
  TFrmConNaturezaOper = class(TFrmConsulta)
    Label2: TLabel;
    EdtNaturezaOper: TEdit;
    DbgNaturezaOperacional: TDBGrid;
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure EdtNaturezaOperKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BtnFecharClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    nato_codigo: string;
    Codf_codigo: string;
  end;

var
  FrmConNaturezaOper: TFrmConNaturezaOper;

implementation

uses Cls_NaturezaOper, dm;

var
  NaturezaOper: TNaturezaOper;
  Tds: TDataSource;
  tq: TQuery;

{$R *.DFM}

procedure TFrmConNaturezaOper.FazConsulta;
begin
  if EdtNaturezaOper.text = '' then EdtNaturezaOper.text := ' ';
  NaturezaOper.Consultar2(tq, Codf_codigo, EdtNaturezaOper.text);
  tq.open;
  DbgNaturezaOperacional.DataSource := tds;
  DbgNaturezaOperacional.Refresh;
end;

procedure TFrmConNaturezaOper.FormCreate(Sender: TObject);
begin
  inherited;
  NaturezaOper := TNaturezaOper.create;
end;

procedure TFrmConNaturezaOper.FormActivate(Sender: TObject);
begin
  inherited;
  tds := TDataSource.create(self);
  tq := Tquery.create(self);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tds.DataSet := tq;
  fazconsulta;
end;

procedure TFrmConNaturezaOper.EdtNaturezaOperKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 12 then FazConsulta;
end;

procedure TFrmConNaturezaOper.BtnFecharClick(Sender: TObject);
begin
  inherited;
  nato_codigo := tq.fieldbyname('nato_codigo').asstring;
  Codf_codigo := tq.fieldbyname('Codf_codigo').AsString;
end;

procedure TFrmConNaturezaOper.FormDestroy(Sender: TObject);
begin
  inherited;
  NaturezaOper.Free;
  tds.free;
  tq.free;
end;

end.
